package com.share.thread;

import java.util.concurrent.CountDownLatch;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;

/**
 * @desc: 核算采集示例 排满10个人开始采集
 * @author:caifan
 * @date:2022/4/2
 */
public class CountDownLatchDemo02 {

    public static void main(String[] args) throws InterruptedException {
        ExecutorService pool = Executors.newFixedThreadPool(10);
        CountDownLatch countDownLatch = new CountDownLatch(1);
        for (int i = 0; i < 10; i++) {
            int finalI = i;
            pool.submit(() -> {
                System.out.println(finalI + "开始排队");
                try {
                    countDownLatch.await();
                    System.out.println(finalI + "开始核算采集");
                } catch (InterruptedException e) {
                    e.printStackTrace();
                }
            });

        }
        Thread.sleep(3000);
        countDownLatch.countDown();
        System.out.println("核酸开始采集");
        pool.shutdown();
    }

}
